﻿using System;
using System.Collections.Generic;
using System.Linq;
using TuxedoLib;

namespace SpaceSquirrel
{
	public static class SquirrelUtil
	{
		public static void DrawBox(Image image, int leftCoord, int topCoord, int cols, int rows)
		{
			int left = leftCoord;
			int top = topCoord;
			int bottom = topCoord + (rows - 1) * 8;
			int right = leftCoord + (cols - 1) * 8;
			image.Blit(ImageLibrary.GetImage("misc/border_nw.png"), left, top);
			image.Blit(ImageLibrary.GetImage("misc/border_ne.png"), right, top);
			image.Blit(ImageLibrary.GetImage("misc/border_se.png"), right, bottom);
			image.Blit(ImageLibrary.GetImage("misc/border_sw.png"), left, bottom);
			int x = left + 8;
			while (x < right)
			{
				image.Blit(ImageLibrary.GetImage("misc/border_n.png"), x, top);
				image.Blit(ImageLibrary.GetImage("misc/border_s.png"), x, bottom);
				x += 8;
			}

			int y = top + 8;
			while (y < bottom)
			{
				image.Blit(ImageLibrary.GetImage("misc/border_w.png"), left, y);
				image.Blit(ImageLibrary.GetImage("misc/border_e.png"), right, y);
				y += 8;
			}

			Draw.RectangleFill(image, Draw.CreateColor(0, 0, 0), left + 8, top + 8, right - left - 8, bottom - top - 8);
		}

		public static T[][] MakeGrid<T>(int width, int height)
		{
			List<T[]> columns = new List<T[]>();
			while (width > 0)
			{
				columns.Add(new T[height]);
				--width;
			}
			return columns.ToArray();
		}
	}
}
